import urllib
from urllib import parse


def str2url(s):
    #s = '9hFaF2FF%_Et%m4F4%538t2i%795E%3pF.265E85.%fnF9742Em33e162_36pA.t6661983%x%6%%74%2i2%22735'
    num_loc = s.find('h')
    rows = int(s[0:num_loc])
    strlen = len(s) - num_loc
    cols = int(strlen/rows)
    right_rows = strlen % rows
    new_s = list(s[num_loc:])
    output = ''
    for i in range(len(new_s)):
        x = i % rows
        y = i / rows
        p = 0
        if x <= right_rows:
            p = x * (cols + 1) + y
        else:
            p = right_rows * (cols + 1) + (x - right_rows) * cols + y
        output += new_s[int(p)]
    return parse.unquote(output).replace('^', '0')


def main():
    s = "5h3%2ae6%1%EE19%F89%E62mFei_x%45diD2d558c1e4%see3lp%896ud5u3vD89n871E7323kD8c56bctA28mt92%56%%3513_5867pc%a%p3%Euo26%E15af3%2_ntD%s317us%EtDi13%%175%327%eB2d5ecet%F.i%%F5E9256E871E7323c3m2iD5%rn1p3ee42ed56ctin2_D43pe3%i%d872315656_.2yc61eae8p2sx.252E%%FE4%175%327%oDi6r8E2a%6sDfbbac5Eul_pu6t19%srD2d2%176D89%E62m6%81333d9%F1inFE1255245215656_.3dx_ee6%6t3%i%f9ba46epin%lus542_i%6%6315f13_5867pv365a9dd"
    result_str = str2url(s)
    print(result_str)


if __name__ == '__main__':
    main()
